package ord2.core;

/**
 * This class stores a pair based parameter. Each parameter has a name and a value
 * associated. Two parameters are equals if they have same name.
 *
 * @author José Ivan
 * @author Edviges
 * 
 */
public final class Parameter {

    private final String name;
    
    private final String value;
    
    /**
     * Creates a parameter.
     * @param name Parameter name
     * @param value Parameter value
     * @throws IllegalArgumentException If name or value is null or name is a empty string.
     */
    public Parameter(String name, String value) {
        
        if (name == null || value == null || name.equals("") || value.equals("")) {
            
            throw new IllegalArgumentException();
        }
        
        this.name = name;
        this.value = value;
    }
    
    /**
     * Returns name associated to this parameter.
     * @return Parameter name
     */
    public String getName() {
        
        return this.name;
    }
    
    /**
     * Gets value that this parameter carries.
     * @return Parameter value.
     */
    public String getValue() {
        
        return this.value;
    }
    
    /**
     * Verifies if object obj is equals to this parameter.
     * @param obj Object to be verified.
     * @return true if obj is a parameter and has the same name of this parameter.
     */
    @Override
    public boolean equals(Object obj) {
        
        if (!(obj instanceof Parameter)) {
            
            return false;
        }
        
        return this.getName().equals(((Parameter) obj).getName());
    }
    
    /**
     * Returns a parameter representation. (name=value)
     * @return A string that represents this parameter
     */
    @Override
    public String toString() {
        
        return this.getName() + "=" + this.getValue();
    }
}
